package com.flying.server.network.msg;

import java.io.UnsupportedEncodingException;

import org.jboss.netty.buffer.ChannelBuffer;

public class OWMsg {
	//MSGTYPE(short) + MSGID(short) + MSGLEN(int)
	public static final int MSG_HEADER_LEN = 8;
	
	private short msgSeq;
	private short msgType;
	private ChannelBuffer bodyBuffer;
	
	
	public OWMsg(short msgType,short msgSeq)
	{
		this(msgType,msgSeq,null);
	}
	public OWMsg(short msgType,short msgSeq,ChannelBuffer buffer)
	{
		this.msgType = msgType;
		this.msgSeq = msgSeq;
		this.bodyBuffer = buffer;
	}
	
	private OWMsg()
	{
	}
	
	public short getMsgType()
	{
		return msgType;
	}
	
	public short getMsgSeq()
	{
		return msgSeq;
	}
	
	public ChannelBuffer getBodyBuffer()
	{
		return bodyBuffer;
	}
	
	public String toString()
	{
		if (bodyBuffer != null)
		{
			try {
				return new String(bodyBuffer.array(),"UTF-8");
			} catch (UnsupportedEncodingException e) {
				return "";
			}
		}
		return "";
	}
	
	public static OWMsg newInstance()
	{
		return new OWMsg();
	}
}
